import java.util.Scanner;
import java.sql.*;
import java.lang.*;
//数据库：RentCar 表1用户 User 表2：管理员 Manager

public class RentCar {
    static String ID;
    static String password;

    public static void main(String[] args) {
        System.out.println("*******欢迎光临腾飞汽车租赁公司********");
        System.out.println("请选择你的身份：1.管理员 2.用户 ");
        Scanner in = new Scanner(System.in);
        int choice = in.nextInt();
        System.out.println("请输入用户名：");
        ID = in.next();
        System.out.println("请输入密码：");
        password = in.next();
        if (choice == 1) {
            try {
                Class.forName("com.mysql.cj.jdbc.Driver");
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            try {
                Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/rentcar","root","123456");
                Statement stm=conn.createStatement();
                ResultSet rs=stm.executeQuery("select * from manager where ID = '"+ID+"'and password ='"+ password+"'");
                if(rs.next()) {
                    System.out.println("管理员登录成功！");
                    rs.close();
                    stm.close();
                    conn.close();
                    manager m =new manager();//管理员操作入口
                    m.welcome();
                }
                else System.out.println("账号密码错误！");

            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        } else {
            try {
                Class.forName("com.mysql.cj.jdbc.Driver");
            } catch (ClassNotFoundException q) {
                q.printStackTrace();
            }
            try {
                Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/rentcar","root","123456");
                Statement stm=conn.createStatement();
                ResultSet rs=stm.executeQuery("select * from user where ID = '"+ID+"'and password ='"+ password+"'");
                if(rs.next()) {
                    System.out.println("用户登录成功");
                    rs.close();
                    stm.close();
                    conn.close();
                    User u = new User();
                    u.welcome();
                }
                else System.out.println("账号密码错误！");
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
    }
}

